import datetime
import pandas as pda
from algorithm.FP_grow_tree import FP_Growth
from algorithm.apriori import Apriori

class SuperMakerDataProcess:
    @classmethod
    def loadDataSet(cls,file_name):
        #加载数据
        all_matrix=pda.read_execl(file_name,header=1)
        product_types=all_matrix.columns[1:]
        for type_name in product_types:
            cols=all_matrix[type_name]
            cols[cols == "T"]=type_name
            cols[cols == "F"]=None
         dataSet = []
         for indexs in all_matrix.index:
             iarray=all_matrix.loc[indexs].values[1:-1]
             dataSet.append(iarray[iarray!=None])
         return dataSet

    @classmethod
    def caculate_with_aprior(cls,dataSet,min_support=0.5):
        start_time=datetime.datetime.now().microsecond
        L,supportData=sorted(supportData.items(),key=lambda item:item[1],reverse=True)
        time_diff=datetime.datetime.now().microsecond-start_time
        for item in sorted_supportData:
            if len(item[0])>=2 and item[1] >=min_support:
                print("       频繁"+str(len(item[0])) +"项集："+str(item[0])+", 支持度： ")
            print("=====================================================")
            print("  算法[aprioti]耗时：" + str(time_diff)+"毫秒"）
            print("=====================================================")

    @classmethod
    def caculate_with_fp_growth(cls,dataSet,min_support=200):
        start_time=datatime.datetime.now().microsecond
        ff=FP_Grow_tree(dataSet,[],min_support)
        time_diff=datetime.datetime.now().microsecond-start_time
        ff.printfrequent()
        print("=====================================================")
        print("  算法[fp_growth]耗时：" + str(time_diff)+"毫秒"）
        print("=====================================================")
          
        
          
            
